import bus from '../libs/bus'

export default {
	bind(el, evt, cb) {
		if (!el) return
		el.addEventListener(evt, cb, false)
	},

  stopPropagation(e) {
    e.stopPropagation()
    e.nativeEvent.stopImmediatePropagation()
  },

	unbind(el, evt, cb) {
		if (!el) return
		el.removeEventListener(evt, cb, false)
	},

	events(el) {
		const obj = {
			bind: (evt, cb) => {
				this.bind(el, evt, cb)
				return obj
			},
			unbind: (evt, cb) => {
				this.unbind(el, evt, cb)
				return obj
			}
		}
		return obj
	},

  bus: bus,

  setMessage(msg) {
    bus.msg = msg
  },

  getMessage() {
    const msg = bus.msg
    bus.msg = ''
    return msg
  }
}
